package cm.cool.web.service.feeds;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;

import cm.cool.web.bean.Feeds;
import cm.cool.web.data.FeedsMapper;
import cm.cool.web.util.respon.PaginationDto;
import cm.cool.web.util.respon.R;
import cm.cool.web.util.respon.ResultEncoding;

@Service
public class FeedsService {
	
	@Autowired
	FeedsMapper feedsMapper;
	
	/**
	 * 条件查找反馈信息
	 * @param feeds
	 * @param paginationDto
	 * @return
	 */
	public R selectByAll(Feeds feeds,PaginationDto paginationDto){
		R r=new R();

		try {
			PageHelper.startPage(paginationDto.getCurrentPageNum(), paginationDto.getPerPageSize());
			paginationDto.setEntitys(feedsMapper.selectByAll(feeds));
			int count = feedsMapper.selectByAllCount(feeds);
			paginationDto.setTotalCount(count);
			paginationDto.setTotalPageNum((int)Math.ceil((count*1.0) / paginationDto.getPerPageSize()));
			r.setData(paginationDto);
		} catch (Exception e) {
			e.printStackTrace();
			r.setCode(ResultEncoding.R_ERR);
			r.setMsg("查询异常");
			return r;
		}
		return r;
	}
	
}
